<template>
    <view>
        <view class="topbar" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
            <text @tap="topbarFn" :class="'item ' + (currentTab == index ? 'active' : '')" :data-idx="index" v-for="(item, index) in topbar" :key="index">{{ item }}</text>
        </view>
        <view class="picli">
            <view @tap="upFn" class="i add ico" :style="'color:rgba(' + rgbcolor + ',.6);border-color:rgba(' + rgbcolor + ',.2);background-color:rgba(' + rgbcolor + ',.1)'">
                
                <text class="h5" :style="'color:rgba(' + rgbcolor + ',.6)'">点击上传</text>
            </view>
            <view class="i" v-for="(item, item_index) in LIST" :key="item_index">
                <image @tap="viewFn" :data-path_b="item.path_b" mode="aspectFill" :src="item.path_s"></image>

                <text @tap.stop.prevent="delFn" class="ico b" :data-id="item.id"></text>
            </view>
        </view>
    </view>
</template>

<script>
var t;
var a = require('../../res/www.a9a.cn.js');
var app = getApp();
export default {
    data() {
        return {
            topbar: ['我的相册'],
            currentTab: 0,
            color: '',
            rgbcolor: '',
            b_list: '',
            LIST: ''
        };
    },
    onLoad: function (t) {
        var that = this;
        app.globalData.chklogin().then(function (t) {
            t || uni.navigateBack();
        });
        app.globalData.get_openid().then(function (t) {
            that.setData({
                color: app.globalData._ZEAI.color,
                rgbcolor: a.c16_rgb(app.globalData._ZEAI.color)
            });
            that.getdata();
        });
    },
    onShow: function () {},
    methods: {
        upFn: function () {
            var that = this;
            uni.chooseMedia({
                count: 1,
                mediaType: ['image'],
                sizeType: ['compressed'],
                sourceType: ['album', 'camera'],
                success: function (n) {
                    uni.uploadFile({
                        url: app.globalData.WWW + '/api/wxxcx/my_photo.php',
                        filePath: n.tempFiles[0].tempFilePath,
                        name: 'pic',
                        formData: {
                            submitok: 'up',
                            openid: t.openid
                        },
                        success: function (t) {
                            if (1 == (t = a.jsoneval(t.data)).flag) {
                                that.getdata();
                            } else {
                                uni.showModal({
                                    content: t.msg,
                                    confirmColor: that.color,
                                    confirmText: '朕知道了',
                                    showCancel: false,
                                    success: function (t) {
                                        uni.navigateBack();
                                    }
                                });
                            }
                        }
                    });
                }
            });
        },

        getdata: function () {
            var that = this;
            t = uni.getStorageSync('COOK_U');
            app.globalData.ajax({
                url: 'my_photo.php',
                data: {
                    submitok: 'index',
                    openid: t.openid
                },
                success: function (t) {
                    if (1 == t.flag) {
                        that.setData({
                            b_list: t.b_list,
                            LIST: t.ARR
                        });
                    } else {
                        uni.showToast({
                            title: t.msg,
                            icon: 'none',
                            mask: true
                        });
                    }
                }
            });
        },

        delFn: function (a) {
            var that = this;
            uni.showModal({
                title: '',
                content: '确定要删除么？',
                confirmColor: that.color,
                cancelText: '取消',
                confirmText: '确定',
                success: function (n) {
                    if (n.confirm) {
                        var c = a.currentTarget.dataset.id;
                        app.globalData.ajax({
                            url: 'my_photo.php',
                            data: {
                                submitok: 'del',
                                id: c,
                                openid: t.openid
                            },
                            success: function (t) {
                                1 == t.flag
                                    ? that.getdata()
                                    : uni.showModal({
                                          content: t.msg,
                                          confirmColor: that.color,
                                          confirmText: '朕知道了',
                                          showCancel: false,
                                          success: function (t) {
                                              uni.navigateBack();
                                          }
                                      });
                            }
                        });
                    }
                }
            });
        },

        viewFn: function (t) {
            var o = t.currentTarget.dataset.path_b;
            a.empty(o) ||
                uni.previewImage({
                    current: o,
                    urls: this.b_list
                });
        },

        topbarFn() {
            console.log('占位：函数 topbarFn 未声明');
        }
    }
};
</script>
<style>
@import 'photo.css';
</style>
